<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物料编号" prop="goodsId">
        <el-input
          v-model="queryParams.goodsId"
          placeholder="请输入物料编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="goodsName">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料简称 简码" prop="goodsShortName">
        <el-input
          v-model="queryParams.goodsShortName"
          placeholder="请输入物料简称 简码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="助记码" prop="pyName">
        <el-input
          v-model="queryParams.pyName"
          placeholder="请输入助记码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="条形码" prop="barcode">
        <el-input
          v-model="queryParams.barcode"
          placeholder="请输入条形码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分类" prop="goodsTypeId">
        <el-input
          v-model="queryParams.goodsTypeId"
          placeholder="请输入分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="规格" prop="specification">
        <el-input
          v-model="queryParams.specification"
          placeholder="请输入规格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="型号" prop="model">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="price">
        <el-input
          v-model="queryParams.price"
          placeholder="请输入单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="物料单位" prop="unit">
        <el-input
          v-model="queryParams.unit"
          placeholder="请输入物料单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="产地" prop="produceArea">
        <el-input
          v-model="queryParams.produceArea"
          placeholder="请输入产地"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="供应商编号" prop="providerId">
        <el-input
          v-model="queryParams.providerId"
          placeholder="请输入供应商编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="海关编码 " prop="hsnumber">
        <el-input
          v-model="queryParams.hsnumber"
          placeholder="请输入海关编码 "
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="ABC分类" prop="abc">
        <el-input
          v-model="queryParams.abc"
          placeholder="请输入ABC分类"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="危险品" prop="hazardous">
        <el-select v-model="queryParams.hazardous" placeholder="请选择危险品" clearable>
          <el-option
            v-for="dict in dict.type.hazardous"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      
      
      <el-form-item label="版本" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入版本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createMan">
        <el-input
          v-model="queryParams.createMan"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改人" prop="updateMan">
        <el-input
          v-model="queryParams.updateMan"
          placeholder="请输入修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" prop="updateDate">
        <el-date-picker clearable
          v-model="queryParams.updateDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="是否是组合商品" prop="scFlag">
        <el-select v-model="queryParams.scFlag" placeholder="请选择是否是组合商品" clearable>
          <el-option
            v-for="dict in dict.type.sc_flag"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
    
    
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:goods:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:goods:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:goods:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:goods:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border
    ref="filterTable" v-loading="loading" :data="goodsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column sortable fixed label="主键" align="center" prop="id" />
      <el-table-column sortable label="物料编号" align="center" prop="goodsId" />
      <el-table-column label="物料名称" align="center" prop="goodsName" />
      <el-table-column label="物料简称 简码" align="center" prop="goodsShortName" />
      <el-table-column sortable label="助记码" align="center" prop="pyName" />
      <el-table-column label="条形码" align="center" prop="barcode" />
      <el-table-column label="分类" align="center" prop="goodsTypeId" />
      <el-table-column label="规格" align="center" prop="specification" />
      <el-table-column label="型号" align="center" prop="model" />
      <el-table-column sortable label="单价" align="center" prop="price" />
      <el-table-column sortable label="长" align="center" prop="glength" />
      <el-table-column sortable label="宽" align="center" prop="gwidth" />
      <el-table-column sortable label="高" align="center" prop="gheight" />
      <el-table-column sortable label="图号" align="center" prop="recoil" />
      <el-table-column sortable label="体积" align="center" prop="gvolume" />
      <el-table-column label="商品重量单位 " align="center" prop="scaleUnit" />
      <el-table-column label="物料单位" align="center" prop="unit" />
      <el-table-column label="库存上限" align="center" prop="warnUp" />
      <el-table-column label="库存下限" align="center" prop="warnDown" />
      <el-table-column label="产地" align="center" prop="produceArea" />
      <el-table-column sortable label="毛重" align="center" prop="grossWeight" />
      <el-table-column sortable label="净重" align="center" prop="netWeight" />
      <el-table-column label="供应商编号" align="center" prop="providerId" />
      <el-table-column label="海关编码 " align="center" prop="hsnumber" />
      <el-table-column label="ABC分类" align="center" prop="abc" />
      <el-table-column label="危险品   0否 1是" align="center" prop="hazardous">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hazardous" :value="scope.row.hazardous"/>
        </template>
      </el-table-column>
      <el-table-column label="存储条件 " align="center" prop="stored" />
      <el-table-column label="保质期" align="center" prop="period" />
      <el-table-column label="保质期单位" align="center" prop="periodunit" />
      <el-table-column label="增值税" align="center" prop="addtax" />
      <el-table-column label="季节" align="center" prop="season" />
      <el-table-column label="关税税率" align="center" prop="tariffrate" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="版本" align="center" prop="version" />
      <el-table-column label="图片" align="center" prop="img" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.img" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createMan" />
      <el-table-column sortable label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="updateMan" />
      <el-table-column sortable label="修改时间" align="center" prop="updateDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否是组合商品 0否 1是" align="center" prop="scFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sc_flag" :value="scope.row.scFlag"/>
        </template>
      </el-table-column>
      <el-table-column sortable label="成本价" align="center" prop="costPrice" />
      <el-table-column label="customerId" align="center" prop="customerId" />
      <el-table-column label="sts1" align="center" prop="sts1" />
      <el-table-column label="isOpen" align="center" prop="isOpen" />
      <el-table-column label="storageAreaId" align="center" prop="storageAreaId" />
      <el-table-column label="zhFlag" align="center" prop="zhFlag" />
      <el-table-column label="semists" align="center" prop="semists" />
      <el-table-column label="materialCharacteristics" align="center" prop="materialCharacteristics" />
      <el-table-column label="recheckdays" align="center" prop="recheckdays" />
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:goods:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:goods:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改商品资料对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
       
        <el-row >
          <!-- 每个el-col是一个栅格单元，span="12"表示占据12/24的宽度，即一半 -->
          <el-col :span="12">
            <el-form-item label="物料编号"  prop="goodsId">
              <el-input v-model="form.goodsId" placeholder="请输入物料编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料名称" prop="goodsName">
              <el-input v-model="form.goodsName" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="物料简称 简码" prop="goodsShortName">
              <el-input v-model="form.goodsShortName" placeholder="请输入物料简称 简码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="助记码" prop="pyName">
              <el-input v-model="form.pyName" placeholder="请输入助记码"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="条形码" prop="barcode">
              <el-input v-model="form.barcode" placeholder="请输入条形码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分类" prop="goodsTypeId">
              <el-input v-model="form.goodsTypeId" placeholder="请输入分类"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="规格" prop="specification">
              <el-input v-model="form.specification" placeholder="请输入规格"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="型号" prop="model">
              <el-input v-model="form.model" placeholder="请输入型号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="单价" prop="price">
              <el-input v-model="form.price" placeholder="请输入单价"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="长" prop="glength">
              <el-input v-model="form.glength" placeholder="请输入长"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="宽" prop="gwidth">
              <el-input v-model="form.gwidth" placeholder="请输入宽"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="高" prop="gheight">
              <el-input v-model="form.gheight" placeholder="请输入高"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="图号" prop="recoil">
              <el-input v-model="form.recoil" placeholder="请输入图号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="体积" prop="gvolume">
              <el-input v-model="form.gvolume" placeholder="请输入体积"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="商品重量单位" prop="scaleUnit">
              <el-input v-model="form.scaleUnit" placeholder="请输入商品重量单位"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料单位" prop="unit">
              <el-input v-model="form.unit" placeholder="请输入物料单位"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="库存上限" prop="warnUp">
              <el-input v-model="form.warnUp" placeholder="请输入库存上限"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存下限" prop="warnDown">
              <el-input v-model="form.warnDown" placeholder="请输入库存下限"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="产地" prop="produceArea">
              <el-input v-model="form.produceArea" placeholder="请输入产地"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毛重" prop="grossWeight">
              <el-input v-model="form.grossWeight" placeholder="请输入毛重"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="净重" prop="netWeight">
              <el-input v-model="form.netWeight" placeholder="请输入净重"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商编号" prop="providerId">
              <el-input v-model="form.providerId" placeholder="请输入供应商编号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="海关编码" prop="hsnumber">
              <el-input v-model="form.hsnumber" placeholder="请输入海关编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="ABC分类" prop="abc">
              <el-input v-model="form.abc" placeholder="请输入ABC分类"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="危险品   0否 1是" prop="hazardous">
              <el-select v-model="form.hazardous" placeholder="请选择危险品   0否 1是">
            <el-option
              v-for="dict in dict.type.hazardous"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="存储条件" prop="stored">
              <el-input v-model="form.stored" placeholder="请输入存储条件"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="保质期" prop="period">
              <el-input v-model="form.period" placeholder="请输入保质期"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保质期单位" prop="periodunit">
              <el-input v-model="form.periodunit" placeholder="请输入保质期单位"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="增值税" prop="addtax">
              <el-input v-model="form.addtax" placeholder="请输入增值税"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="季节" prop="season">
              <el-input v-model="form.season" placeholder="请输入季节"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="关税税率" prop="tariffrate">
              <el-input v-model="form.tariffrate" placeholder="请输入关税税率"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="版本" prop="version">
              <el-input v-model="form.version" placeholder="请输入版本"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="图片" prop="img">
              <image-upload v-model="form.img"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="是否是组合商品 0否 1是" prop="scFlag">
              <el-select v-model="form.scFlag" placeholder="请选择是否是组合商品 0否 1是">
            <el-option
              v-for="dict in dict.type.sc_flag"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成本价" prop="costPrice">
              <el-input v-model="form.costPrice" placeholder="请输入成本价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="customerId" prop="customerId">
              <el-input v-model="form.customerId" placeholder="请输入customerId"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="sts1" prop="sts1">
              <el-input v-model="form.sts1" placeholder="请输入sts1"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="isOpen" prop="isOpen">
              <el-input v-model="form.isOpen" placeholder="请输入isOpen"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="storageAreaId" prop="storageAreaId">
              <el-input v-model="form.storageAreaId" placeholder="请输入storageAreaId"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="zhFlag" prop="zhFlag">
              <el-input v-model="form.zhFlag" placeholder="请输入zhFlag"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="semists" prop="semists">
              <el-input v-model="form.semists" placeholder="请输入semists"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row >
          <el-col :span="12">
            <el-form-item label="materialCharacteristics" prop="materialCharacteristics">
              <el-input v-model="form.materialCharacteristics" placeholder="请输入materialCharacteristics"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="recheckdays" prop="recheckdays">
              <el-input v-model="form.recheckdays" placeholder="请输入recheckdays"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGoods, getGoods, delGoods, addGoods, updateGoods } from "@/api/system/goods";

export default {
  name: "Goods",
  dicts: ['status', 'hazardous', 'sc_flag'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 商品资料表格数据
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsId: null,
        goodsName: null,
        goodsShortName: null,
        pyName: null,
        barcode: null,
        goodsTypeId: null,
        specification: null,
        model: null,
        price: null,
        glength: null,
        gwidth: null,
        gheight: null,
        recoil: null,
        gvolume: null,
        scaleUnit: null,
        unit: null,
        warnUp: null,
        warnDown: null,
        produceArea: null,
        grossWeight: null,
        netWeight: null,
        providerId: null,
        hsnumber: null,
        abc: null,
        hazardous: null,
        stored: null,
        period: null,
        periodunit: null,
        addtax: null,
        season: null,
        tariffrate: null,
        status: null,
        version: null,
        img: null,
        createMan: null,
        createDate: null,
        updateMan: null,
        updateDate: null,
        scFlag: null,
        costPrice: null,
        customerId: null,
        sts1: null,
        isOpen: null,
        storageAreaId: null,
        zhFlag: null,
        semists: null,
        materialCharacteristics: null,
        recheckdays: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        goodsId: [
          { required: true, message: "物料编号不能为空", trigger: "blur" }
        ],
        goodsName: [
          { required: true, message: "物料名称不能为空", trigger: "blur" }
        ],
        goodsShortName: [
          { required: true, message: "物料简称 简码不能为空", trigger: "blur" }
        ],
        
        goodsTypeId: [
          { required: true, message: "分类不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "单价不能为空", trigger: "blur" }
        ],
        specification: [
          { required: true, message: "规格不能为空", trigger: "blur" }
        ],
        model: [
          { required: true, message: "型号不能为空", trigger: "blur" }
        ],
        price: [
        { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        glength: [
        { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        gwidth: [
        { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        gheight: [
        { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        gvolume: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        warnUp: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        warnDown: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        grossWeight: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        netWeight: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        period: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        addtax: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        tariffrate: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        costPrice: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
        recheckdays: [
          { required: false,validator: this.validateNumber, trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    validateNumber(rule, value, callback) {  
      const regex = /^\d+(\.\d+)?$/; // 正则表达式，匹配整数或小数  
  
  // 检查是否为空，如果允许空值则通过验证  
  if (value == null || value === '') {  
    // 这里没有错误，因为允许空值  
    callback(); // 调用callback无参数表示验证通过  
    return; // 退出函数  
  }  
  
  // 如果值不为空，则检查是否符合正则表达式  
  if (!regex.test(value)) {  
    // 如果值不符合正则表达式，返回错误  
    return callback(new Error('请输入有效的数字（可以包含小数）'));  
  }  
  
  // 如果验证通过，调用callback  
  callback();  
  },
    /** 查询商品资料列表 */
    getList() {
      this.loading = true;
      listGoods(this.queryParams).then(response => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        goodsId: null,
        goodsName: null,
        goodsShortName: null,
        pyName: null,
        barcode: null,
        goodsTypeId: null,
        specification: null,
        model: null,
        price: null,
        glength: null,
        gwidth: null,
        gheight: null,
        recoil: null,
        gvolume: null,
        scaleUnit: null,
        unit: null,
        warnUp: null,
        warnDown: null,
        produceArea: null,
        grossWeight: null,
        netWeight: null,
        providerId: null,
        hsnumber: null,
        abc: null,
        hazardous: null,
        stored: null,
        period: null,
        periodunit: null,
        addtax: null,
        season: null,
        tariffrate: null,
        remark: null,
        status: null,
        version: null,
        img: null,
        createMan: null,
        createDate: null,
        updateMan: null,
        updateDate: null,
        scFlag: null,
        costPrice: null,
        customerId: null,
        sts1: null,
        isOpen: null,
        storageAreaId: null,
        zhFlag: null,
        semists: null,
        updateBy: null,
        materialCharacteristics: null,
        recheckdays: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品资料";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getGoods(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品资料";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGoods(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGoods(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除商品资料编号为"' + ids + '"的数据项？').then(function() {
        return delGoods(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/goods/export', {
        ...this.queryParams
      }, `goods_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
